package com.search.controller;

import com.search.entity.BorrowBook;
import com.search.service.Add2Service;
import com.search.service.Add3Service;
import com.search.service.Add5Service;
import com.search.service.AddService;
import com.search.service.impl.Add3ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;

@RestController
@Slf4j
public class HelloController {


    @Autowired
    private Add2Service add2Service;

    @Autowired
    private Add3Service add3Service;

    @Autowired
    private Add5Service add5Service;

    AtomicInteger num = new AtomicInteger(0);

    @RequestMapping("/hello")
    public String hello(){
        log.info(Thread.currentThread().getName()+"info"+num.incrementAndGet()+"--"+Thread.currentThread().getId());
        BorrowBook book = new BorrowBook();
        log.info(book.hashCode()+"");
        log.info(System.identityHashCode(book)+"");
        //log.debug("debug");
        //System.out.println("hello");
        return "hello333";
    }


    @RequestMapping("/add")
    public int add() throws InterruptedException {
        int num=0;
        log.info("ad");
        do {
            Thread.sleep(100);
            num++;
        }while (num<200);

        System.out.println("hello");
        return num;
    }

    @RequestMapping("/add2")
    public int add2() throws InterruptedException {
        AddService addService = new AddService();
        return addService.add();
    }

    @RequestMapping("/add3")
    public int add3() throws InterruptedException {
        log.info(Thread.currentThread().getName()+"controller");
        return add2Service.add();
    }

    @RequestMapping("/add4")
    public int add4() throws InterruptedException {
        add3Service = new Add3ServiceImpl();
        return add3Service.add();
    }

    @RequestMapping("/add5")
    public int add5() throws InterruptedException {
        return add5Service.add();
    }
}
